Questions
13 of 20
1What is a Web Worker and why do we need it? What problem does it solve in the browser?
2What are the three types of Web Workers? How do they differ from each other?
3How do you create a Web Worker and communicate with it?
4What is the postMessage / onmessage pattern? Is communication synchronous or asynchronous?
5What APIs and features are not available inside a Web Worker? (e.g., DOM, window, document)
6What is the Structured Clone Algorithm? How is it different from JSON serialization? What types can and cannot be cloned?
7What are Transferable Objects? How does transferring an ArrayBuffer differ from cloning it, and why does it matter for performance?
8How do you handle errors inside a Web Worker? What events are available and what information do they expose?
9What is a Shared Worker? How can multiple browser tabs communicate through one? What are its limitations?
10How do you terminate a Web Worker? What's the difference between worker.terminate() and self.close()?
11How would you architect a thread pool using Web Workers to process a large task queue efficiently?
12What is SharedArrayBuffer and Atomics? How do they enable true shared memory between the main thread and workers? What security headers are required to use them?
13What are the performance trade-offs of using Web Workers? When can they actually hurt performance (e.g., small tasks, frequent postMessage calls)?
14How would you use Web Workers with WebAssembly (WASM) for CPU-intensive tasks? What makes this combination powerful?
15How do Module Workers work (type: 'module')? What advantages do they offer over classic workers?
16In a React or Vue app, how would you integrate a Web Worker cleanly without breaking the component lifecycle? Have you used libraries like comlink — how does it simplify the worker communication model?
17What is the lifecycle of a Service Worker (install → activate → fetch)? How do you handle cache versioning and old worker cleanup?
18What is the difference between cache.put(), cache.add(), and cache.addAll()? How do you implement a cache-first vs network-first strategy?
19How do you communicate between a Service Worker and the main thread? What is the role of BroadcastChannel vs postMessage here?
20Can Web Workers access localStorage?
13 / 20

What are the performance trade-offs of using Web Workers? When can they actually hurt performance (e.g., small tasks, frequent postMessage calls)?

Workers add overhead for thread creation, message serialization, and data transfer. For small tasks, the overhead may exceed benefits. Frequent postMessage with large data can flood the event loop.

Use workers for CPU-intensive tasks (e.g., image processing, parsing) that take >10ms. Avoid workers for trivial tasks or when data transfer costs exceed processing gains. Minimize postMessage frequency; batch data when possible.